<!--App版本新增/编辑-->
<template>
  <div class="app-container-add">
    <el-dialog
      v-dialogDrag
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      class="dialogStyleSmall"
      :before-close="cancel"
    >
      <el-form
        v-if="dialogVisible"
        ref="addForm"
        class="dialog-form"
        :model="formData"
        label-width="80px"
      >
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="App版本" prop="versionNum">
              <span class="detail-info">{{ formData.versionNum }} </span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="版本名称" prop="versionName">
              <span class="detail-info">{{ formData.versionName }} </span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="强制更新" prop="isRenew">
              <el-radio-group v-model="formData.isRenew" disabled>
                <el-radio label="0">是</el-radio>
                <el-radio label="1">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="版本信息" prop="versionInfo">
              <span class="detail-info">{{ formData.versionInfo }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="安装文件" prop="updateAddress">
              <FileUplodeOne
                ref="fileUplode"
                :read-only="readOnly"
                :edit-file-list="FileList"
                @getFileIdsList="getFileList"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
// 页面接口
import { getMobileInfoById } from '@/api/system/AppEdition/index'
// 附件上传
import FileUplodeOne from '@/components/Upload/FileUplodeOne'
export default {
  name: 'Add',
  components: {
    FileUplodeOne
  },
  data() {
    return {
      /* 新增 start*/
      dialogTitle: '', // 弹层标题
      dialogVisible: false, // 弹层是否显示
      btnDisabled: false, // 确定按钮
      formData: { // 新增数据
        versionNum: '', // App版本
        versionInfo: '', // 版本信息
        updateAddressList: ''// App安装包
      },
      readOnly: true,
      FileList: []// 附件
    }
  },
  computed: {
    start() {
      return (num) => { // 自定义评分start
        const [integer, decimal] = num.toFixed(1).split('.')
        const arr = []
        for (let i = 0; i < integer; i++) {
          arr.push('off') // 满星
        }

        +decimal !== 0 && arr.push('half') // 半星

        for (let j = 0; j < 5 - arr.length; j) {
          arr.push('no') // 没星
        }
        console.log(arr)
        return arr
      }
    }
  },
  mounted() {
  },
  methods: {
    /* 详情弹层 start*/
    // 从父组件获取参数的方法
    handleAdd(title, id) {
      this.dialogVisible = true
      this.dialogTitle = title
      if (id) {
        this.getDetailById(id)
      }
    },
    // 获取详情
    getDetailById(id) {
      getMobileInfoById(id).then(res => {
        if (res) {
          this.formData = { ...res.data }
          if (res.data.updateAddressList && res.data.updateAddressList.length > 0) {
            this.FileList = res.data.updateAddressList
          }
        }
      })
    },
    // 关闭
    cancel() {
      this.dialogVisible = false
    },
    /* 详情弹层 end*/
    /** ************ 文件上传start *******************/
    // 接受文件上传 组件 回传过来的文件id
    getFileList(fileIdsList, deleteFileIds) {
      this.formData.updateAddressList = fileIdsList
    }
    /** ************ 文件上传end *******************/
  }
}
</script>

